<template>
  <div>
    <el-table
        :data="comments"
        stripe
        style="width: 100%">
        <el-table-column 
          prop="id"
          label="编号"
          width="130"
          align="center">
        </el-table-column>
        <el-table-column
          prop="content"
          label="评论内容"
          width="200"
          align="center">
        </el-table-column>
        <el-table-column
          prop="commentTime"
          label="评论时间"
          width="270"
          align="center">
        </el-table-column>
        <el-table-column
          prop="orderId"
          label="产品ID"
          width="270"
          align="center">
        </el-table-column>
        <el-table-column
          prop="status"
          label="状态"
          width="200"
          align="center">
        </el-table-column>
        <el-table-column
          label="操作"
          width="200"
          align="center">
          <template slot-scope="scope">
        <el-button @click="handleClick(scope.row)" type="text" size="small">删除</el-button>
        <el-button v-if="scope.row.status=='审核通过'"  type="text" size="small" @click="examine(scope.row)">通过审核</el-button>
        <el-button v-else type="text" size="small" @click="reExamine(scope.row)">拒绝审核</el-button>
      </template>
        </el-table-column>
      </el-table>

      <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="currentPage1"
            :page-size="pageSize"
            layout="total, prev, pager, next"
            :total="total">
            </el-pagination>

  </div>
</template>
        



<script>
import qs from 'querystring';

export default {
    data(){
        return{
          currentPage1:1,
          pageSize:6,
          total:0,
          comments:[],
        }
    },
    methods:{
        //审核功能
        examine(row){
          var self=this;
          console.log(row.status);
            self.$axios.get("/comment/commentRefuseExamine",{params:{commentid:row.id}}).then(response=>{
              self.status="审核不通过";
              self.findAll();
            })
          
        },

        reExamine(row){
          this.$axios.get("/comment/commentExamine",{params:{commentid:row.id}}).then(response=>{
              this.status="审核通过";
              this.findAll();
        })
        },

        //分页封装函数
        findAll(){
          var data={
              page:this.currentPage1-1,
              pageSize:this.pageSize,
            }
          this.$axios.post("/comment/query",qs.stringify(data)).then(response=>{
              this.comments=response.data.data.list;
              this.total=response.data.data.total;
              console.log(this.comments);
          });
      },
        //删除函数
      handleClick(row){
          var id=row.id;
          var self=this;
          this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          self.$axios.get("/comment/deleteById",{params:{id}}).then((response)=>{
              if(response.data.status==200){
                this.$message({
                    type: 'success',
                    message: '删除成功!'
                  });
                  self.findAll();
              }else{
                  this.$message.error("删除失败");
              }
          })
          
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
          
      },

      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
          //根据分页发送请求
         // console.log(val);
          this.currentPage1=val;
          this.findAll();
         
      },
    },
    
    created(){
        this.findAll();
    }
}
</script>